package com.guaju.yueshangLife.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.guaju.yueshangLife.R;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLinearLayout;

public class SeperateLine extends AutoFrameLayout {

    private LayoutInflater layoutInflater;
    private TextView seperate_title;
    private LinearLayout ll_container;

    public SeperateLine(Context context) {
        super(context);
        init();
    }

    private void init() {
        layoutInflater = LayoutInflater.from(getContext());
        View view = layoutInflater.inflate(R.layout.seperate_line, this);
        seperate_title = (TextView) view.findViewById(R.id.seperate_title);
        ll_container = (LinearLayout) view.findViewById(R.id.ll_container);
    }

    public SeperateLine(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.seperate_line);
        int seperate_line_title_style = typedArray.getInt(R.styleable.seperate_line_title_style, 0);
        if (seperate_line_title_style == 1) {
            seperate_title.setTextAppearance(getContext(), R.style.text_bold);
        } else {
            seperate_title.setTextAppearance(getContext(), R.style.text_normal);
        }
        String seperate_value = typedArray.getString(R.styleable.seperate_line_title_name);
        if (!TextUtils.isEmpty(seperate_value)) {
            seperate_title.setText(seperate_value);
        }
        int bg_color = typedArray.getResourceId(R.styleable.seperate_line_bg, R.color.gray_f2);
        ll_container.setBackgroundColor(getResources().getColor(bg_color));
    }

    public SeperateLine(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void setTextBold() {
        seperate_title.setTextAppearance(getContext(), R.style.text_bold);
    }

    public void setTextNormal() {
        seperate_title.setTextAppearance(getContext(), R.style.text_normal);
    }

    public void setText(String name) {
        seperate_title.setText(name);
    }

    public void setText(int res) {
        seperate_title.setText(res);
    }

}
